<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html>
<html>
<head>
<!--
		Charisma v1.0.0

		Copyright 2012 Muhammad Usman
		Licensed under the Apache License v2.0
		http://www.apache.org/licenses/LICENSE-2.0

		http://usman.it
		http://twitter.com/halalit_usman
	-->
<meta charset="utf-8">
	<title>友宝后台管理系统</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description"
	content="Charisma, a fully featured, responsive, HTML5, Bootstrap admin template.">
<meta name="author" content="Muhammad Usman">

<!-- The styles -->
<link id="bs-css" href="css/bootstrap-cerulean.css" rel="stylesheet">
<style type="text/css">
body {
	padding-bottom: 40px;
}

.sidebar-nav {
	padding: 9px 0;
}
</style>
<link href="css/bootstrap-responsive.css" rel="stylesheet">
<link href="css/charisma-app.css" rel="stylesheet">
<link href="css/jquery-ui-1.8.21.custom.css" rel="stylesheet">
<link href='css/fullcalendar.css' rel='stylesheet'>
<link href='css/fullcalendar.print.css' rel='stylesheet' media='print'>
<link href='css/chosen.css' rel='stylesheet'>
<link href='css/uniform.default.css' rel='stylesheet'>
<link href='css/colorbox.css' rel='stylesheet'>
<link href='css/jquery.cleditor.css' rel='stylesheet'>
<link href='css/jquery.noty.css' rel='stylesheet'>
<link href='css/noty_theme_default.css' rel='stylesheet'>
<link href='css/elfinder.min.css' rel='stylesheet'>
<link href='css/elfinder.theme.css' rel='stylesheet'>
<link href='css/jquery.iphone.toggle.css' rel='stylesheet'>
<link href='css/opa-icons.css' rel='stylesheet'>
<link href='css/uploadify.css' rel='stylesheet'>

<!-- The HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
	  <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
	<![endif]-->

<!-- The fav icon -->
<link rel="shortcut icon" href="img/favicon.ico">

</head>

<body>
	<s:include value="header.jsp" />
	<!-- topbar ends -->
	<div class="container-fluid">
		<div class="row-fluid">

			<s:include value="left.jsp" />

			<noscript>
				<div class="alert alert-block span10">
					<h4 class="alert-heading">Warning!</h4>
					<p>
						You need to have <a href="http://en.wikipedia.org/wiki/JavaScript"
							target="_blank">JavaScript</a> enabled to use this site.
					</p>
				</div>
			</noscript>

			<div id="content" class="span10">
				<!-- content starts -->


				<div>
					<ul class="breadcrumb">
						<li><a href="index">主页</a> <span class="divider">/</span></li>
						<li><a href="#">快递员信息添加</a></li>
					</ul>
				</div>

				<div class="sortable row-fluid">
					<div class="box-content">
						<form class="form-horizontal" action="registerCourier" method="post">
						  <fieldset>
								<div class="control-group">
									<label class="control-label" for="company">请选择公司：</label>
									<div class="controls">
										<select id="company" name="company" style="width: 250px;">
											<s:iterator value="companies" status="st">
												<option value="<s:property value="companyId" />">
													<s:property value="companyName" />
												</option>
											</s:iterator>
										</select>
									</div>
								</div>
								<div class="control-group">
									<label class="control-label" for="branch">请选择快递网点：</label>
									<div class="controls">
										<select id="expressId" name="expressId" style="width: 250px;">
											<%-- <s:iterator value="expressBranchs" status="st" var="expressName">
												<option value="<s:property value="#expressName" />">
													<s:property value="#expressName" />
												</option>
											</s:iterator> --%>
										</select>
									</div>
								</div>
								<div class="control-group">
								  <label class="control-label" for="typeahead">是否负责人:</label>
								  <div class="controls">
								  		<select id="role" name="courier.role" style="width: 250px;">
											<option value="0">否</option>
											<option value="1">是</option>
										</select>
								  </div>
								</div>
								<div class="control-group">
								  <label class="control-label" for="typeahead">姓名:</label>
								  <div class="controls">
									<input name="courier.courierName" type="text" class="span4 typeahead" id="courierName" data-items="2" style="float: left;"/>
								  </div>
								</div>
								<div class="control-group">
								  <label class="control-label" for="typeahead">手机号码:</label>
								  <div class="controls">
									<input name="courier.mobileNum" type="text" maxlength="11" class="span4 typeahead" id="mobileNum" data-items="2" style="float: left;"/>
								  </div>
								</div>
								<div class="control-group">
								  <label class="control-label" for="typeahead">密码:</label>
								  <div class="controls">
									<input name="courier.pwd" type="password" maxlength="6" class="span4 typeahead" id="pwd" data-items="2" style="float: left;"/>
								  </div>
								</div>
								<div class="control-group">
								  <label class="control-label" for="typeahead">确认密码:</label>
								  <div class="controls">
									<input id="rePwd" type="password" maxlength="6" class="span4 typeahead" id="pwd" data-items="2" style="float: left;"/>
								  </div>
								</div>
								<%-- <div class="control-group">
								  <label class="control-label" for="typeahead">序列号:</label>
								  <div class="controls">
								  <select id="cardID" style="width: 250px;">
								  		<option value="">自己的卡</option>
										<s:iterator value="cards" status="st">
											<option value="<s:property value="rfid" />">
												<s:property value="sernum" />
											</option>
										</s:iterator>
									</select>
								  </div>
								</div> --%>
								<div class="control-group">
								  <label class="control-label" for="typeahead">序列号:</label>
								  <div class="controls">
									<input id="sernum" name="courier.sernum" type="text" maxlength="11" class="span4 typeahead" data-items="2" style="float: left;"/>
								  </div>
								</div>
								<div class="control-group">
								  <label class="control-label" for="typeahead">rfid:</label>
								  <div class="controls">
									<input id="rfid" name="courier.rfid" type="text" readonly="readonly" class="span4 typeahead" data-items="2" style="float: left;"/>
								  </div>
								</div>
								<div class="control-group">
								  <label class="control-label" for="typeahead">身份证:</label>
								  <div class="controls">
									<input name="courier.IDcard" type="text" class="span4 typeahead" maxlength="18" id="IDcard" data-items="2" style="float: left;"/>
								  </div>
								</div>
								<div class="control-group">
								  <label class="control-label" for="typeahead">地址:</label>
								  <div class="controls">
									<input name="courier.addr" type="text" class="span4 typeahead" id="addr" data-items="2" style="float: left;"/>
								  </div>
								</div>
								<div class="control-group">
								  <label class="control-label" for="typeahead">备注:</label>
								  <div class="controls">
									<textarea name="courier.courierComment" type="text" style="width: 400px;height: 100px;"></textarea>
								  </div>
								</div>
							  <div class="form-actions">
								<button type="button" class="btn btn-primary" id="subBtn">增加</button>
								<button class="btn" type="button" onclick="window.history.go(-1);">Cancel</button>
							  </div>																					
						  </fieldset>
						</form> 
					</div>
				</div>
				<!-- content ends -->
			</div>
			<!--/#content.span10-->
		</div>
		<!--/fluid-row-->

		<hr>

		<div class="modal hide fade" id="myModal">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal">Ã</button>
				<h3>Settings</h3>
			</div>
			<div class="modal-body">
				<p>Here settings can be configured...</p>
			</div>
			<div class="modal-footer">
				<a href="#" class="btn" data-dismiss="modal">Close</a> <a href="#"
					class="btn btn-primary">Save changes</a>
			</div>
		</div>

	<s:include value="footer.jsp" />

	</div>
	<!--/.fluid-container-->

	<!-- external javascript
	================================================== -->
	<!-- Placed at the end of the document so the pages load faster -->

	<!-- jQuery -->
	<script src="js/jquery-1.7.2.min.js"></script>
	<!-- jQuery UI -->
	<script src="js/jquery-ui-1.8.21.custom.min.js"></script>
	<!-- transition / effect library -->
	<script src="js/bootstrap-transition.js"></script>
	<!-- alert enhancer library -->
	<script src="js/bootstrap-alert.js"></script>
	<!-- modal / dialog library -->
	<script src="js/bootstrap-modal.js"></script>
	<!-- custom dropdown library -->
	<script src="js/bootstrap-dropdown.js"></script>
	<!-- scrolspy library -->
	<script src="js/bootstrap-scrollspy.js"></script>
	<!-- library for creating tabs -->
	<script src="js/bootstrap-tab.js"></script>
	<!-- library for advanced tooltip -->
	<script src="js/bootstrap-tooltip.js"></script>
	<!-- popover effect library -->
	<script src="js/bootstrap-popover.js"></script>
	<!-- button enhancer library -->
	<script src="js/bootstrap-button.js"></script>
	<!-- accordion library (optional, not used in demo) -->
	<script src="js/bootstrap-collapse.js"></script>
	<!-- carousel slideshow library (optional, not used in demo) -->
	<script src="js/bootstrap-carousel.js"></script>
	<!-- autocomplete library -->
	<script src="js/bootstrap-typeahead.js"></script>
	<!-- tour library -->
	<script src="js/bootstrap-tour.js"></script>
	<!-- library for cookie management -->
	<script src="js/jquery.cookie.js"></script>
	<!-- calander plugin -->
	<script src='js/fullcalendar.min.js'></script>
	<!-- data table plugin -->
	<script src='js/jquery.dataTables.min.js'></script>

	<!-- chart libraries start -->
	<script src="js/excanvas.js"></script>
	<script src="js/jquery.flot.min.js"></script>
	<script src="js/jquery.flot.pie.min.js"></script>
	<script src="js/jquery.flot.stack.js"></script>
	<script src="js/jquery.flot.resize.min.js"></script>
	<!-- chart libraries end -->

	<!-- select or dropdown enhancer -->
	<script src="js/jquery.chosen.min.js"></script>
	<!-- checkbox, radio, and file input styler -->
	<script src="js/jquery.uniform.min.js"></script>
	<!-- plugin for gallery image view -->
	<script src="js/jquery.colorbox.min.js"></script>
	<!-- rich text editor library -->
	<script src="js/jquery.cleditor.min.js"></script>
	<!-- notification plugin -->
	<script src="js/jquery.noty.js"></script>
	<!-- file manager library -->
	<script src="js/jquery.elfinder.min.js"></script>
	<!-- star rating plugin -->
	<script src="js/jquery.raty.min.js"></script>
	<!-- for iOS style toggle switch -->
	<script src="js/jquery.iphone.toggle.js"></script>
	<!-- autogrowing textarea plugin -->
	<script src="js/jquery.autogrow-textarea.js"></script>
	<!-- multiple file upload plugin -->
	<script src="js/jquery.uploadify-3.1.min.js"></script>
	<!-- history.js for cross-browser state change on ajax -->
	<script src="js/jquery.history.js"></script>
	<!-- application script for Charisma demo -->
	<script src="js/charisma.js"></script>
<script type="text/javascript">
$("#sernum").keyup(function(){
	$(this).val($(this).val().toUpperCase());
	$("#rfid").val("");
	 $.post("courier!getRfid?sernum="+$("#sernum").val(),function(v){
		   if(v!=1){
			   $("#rfid").val(v);
		   }
	  });
});
$("#subBtn").click(function(){
	var mobileNum = false;
	var rfid = false;
	if($("#courierName").val()==""){   //验证快递员姓名不能为空
		alert("快递员姓名不能为空！");
		 return false;
	 }
	if($("#mobileNum").val()==""){   //验证手机号码不能为空
		alert("手机号码不能为空！");
		mobileNum = false;
		 return false;
	 }else{
	     var  re=/^((13[0-9])|(15[^4,\\D])|(18[0-9]))\\d{8}$/;
		 if($("#mobileNum").val().length!=11||re.test($("#mobileNum").val())){
			 alert("手机号码格式错误！");
			 mobileNum = false;
			 return false;
		 }else{
			 $.ajax({
				  url: "courier!checkValue?flag=mobileNum&value="+$("#mobileNum").val(),
				  async: false,
				  success: function(data){
					  if(data==1){
						  alert("该手机号码已存在，请重新输入！");
						   mobileNum = false;
						   return false;
					   }else{
						   mobileNum = true;
					   }
				  }
				});
			 /* $.post("courier!checkValue?flag=mobileNum&value="+$("#mobileNum").val(),function(v){
				   if(v==1){
					   alert("改手机号码已存在，请重新输入！");
					   mobileNum = false;
					   return false;
				   }else{
					   mobileNum = true;
				   }
			  }); */
		 }
	 }
	if($("#pwd").val()==""){   //验证线下密码
		alert("密码不能为空！");
	 	 return false;
	 }else if($("#pwd").val().length!=6){
		 alert("密码长度太短，请输入6位数字！");
		 return false;
	 }else{
	     var  re=/^[0-9]{6}$/;
		 if(!re.test($("#pwd").val())){
			 alert("密码只能为数字！");
			 return false;
		 }
	 }
	if($("#rePwd").val()!=$("#pwd").val()){   //验证线下密码
		alert("两次输入的密码不一致！");
	 	 return false;
	 }
	if($("#sernum").val()!=""){   //验证rfid唯一
		 /* if($("#sernum").val().length!=11){
			 alert("序列号为11位！！！！");
			 return false;
		 } */
		if($("#rfid").val()==""){
			alert("该卡不存在，请重新输入！！！！");
			rfid = false;
			 return false;
		}else{
			$.ajax({
				  url: "courier!checkValue?flag=rfid&value="+$("#rfid").val(),
				  async: false,
				  success: function(data){
					  if(data==1){
						  alert("该授权卡已被使用，请重新选择！");
						   rfid = false;
						   return false;
					   }else{
						   rfid = true;
					   }
				  }
				});
			 /* $.post("courier!checkValue?flag=rfid&value="+$("#rfid").val(),function(v){
				   if(v==1){
					   alert("该授权卡已被使用，请重新选择！");
					   rfid = false;
					   return false;
				   }else{
					   rfid = true;
				   }
			  }); */
		}
	}else{
		rfid = true;
	}
	if($("#IDcard").val()==""){   //验证身份证
		alert("身份证不能为空！");
	 	 return false;
	 }else if($("#IDcard").val().length!=18){
		 alert("身份证长度太短！");
		 return false;
	 }else{
	     var  re=/^[1-9]([0-9]{14}|[0-9]{18})$/;
		 if(re.test($("#IDcard").val())){
			 alert("身份证不能包含特殊字符！");
			 return false;
		 }
	 }
	if($("#addr").val()==""){   //验证地址
		alert("地址不能为空！");
	 	 return false;
	 }else{
	     var  re=/^[a-zA-Z0-9\u4E00-\u9FA5]+$/;
		 if(!re.test($("#addr").val())){
			 alert("地址不能包含特殊字符！");
			 return false;
		 }
	 }
	/* $.ajax({
			  url: "user!checkValue?flag="+flag+"&value="+value+"&userID="+userID,
			  async: false,
			  success: function(data){
				  if(data==1){
					   checktips(para,"&nbsp;(*该项已存在，请重新输入！)");
					   setSpan(para,"false");
				   }else{
					   setSpan(para,"true");
				   }
			  }
			}); */
			if(mobileNum==true&&rfid==true){
				alert("提交成功！");
				$("form").submit();
			}else{
				alert("提交失败！");
			}
});
$("#role").change(function(){
	if($("#role").val()==1){
	$.ajax({
		  url: "courier!checkExpress?expressId="+$("#expressId").val(),
		  async: false,
		  success: function(data){
			  if(data==1){
				  alert("该快递网点负责人已存在！");
				   $("#role").val("0");
			   }
		  }
		});
	}
});
$("#company").change(function(){
	var content="";
	$.ajax({
	 url:"getBranchAndCompany?company="+$(this).val(),
	 dataType:"json",
	 success: function(data) {
				$("#expressId").empty();
				for(var i=0;i<data.length;i++){
					/* console.log("branch: "+data[i].expressName); */
					content+="<option value='"+data[i].expressId+"'>"+data[i].expressName+"</option>";
				}
				$("#expressId").html(content);
		 }
	});
});
$(function(){
	$("#company").change();
});
</script>

</body>
</html>
